<template id="table1">
  <div>
  <table>
    <tr>
      <th>编号</th>
      <th>名称</th>
      <th>地址</th>
      <th>联系方式</th>
      <th>负责人</th>
    </tr>
    <tr v-for="(index) in list">
      <td v-for="(value) in index">{{value}}</td>
      <td> <button @click="del(index.id)">删除</button>/
        <button @click="update(index)">修改</button></td>
    </tr>
  </table>
    <div>
      <form>
        姓名: <input v-model="author.name"/><br>
        地址:<input v-model="author.site"><br>
        联系方式:<input v-model="author.contact"><br>
        联系人：<input v-model="author.the"><br>
        <button type="submit" @click="add()">提交</button>
      </form>
    </div>
    <div>
      <form>
        id:<input  v-model="author1.id" /><br>
        姓名: <input v-model="author1.name"/><br>
        地址:<input v-model="author1.site"><br>
        联系方式:<input v-model="author1.contact"><br>
        联系人：<input v-model="author1.the"><br>
        <button type="submit" @click="upd()">提交</button>
      </form>
    </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: 'PublisherManager',
  data () {
    return {
      list : [],
      author1:{id:"",name:"",site:"",contact:"",the:""},
      author:{name:"",site:"",contact:"",the:""}
    }
  },
  components:{
    "table1":{
      template: "table1",
      props:{
        list: [],
        title:""
      }
    }
  },
  created () {
    this.$http.post('/publisher/select').then(data=>{
      this.list = data;
    })
  },
  methods:{
    del(id){
      // alert(id);
      // var params = new URLSearchParams();
      // params.append('id', '70');
      this.author.id=id;
      alert(id);
      this.$http.post("/publisher/delete",this.author);
      //$.post("http://localhost:8080/texture/select");
      window.location.reload();
    },
    add(){
      this.$http.post("/publisher/insert", this.author).then(add=>{
        //alert(add);
        if(add>0){
          alert("添加成功");
          window.location.reload();
        }else{
          alert("添加失败")
        }
      })
    },
    update(item){
      this.author1.id=item.id;
      this.author1.name=item.name;
     this.author1.site=item.site;
     this.author1.contact=item.contact;
     this.author1.the=item.the;
    },
    upd(){
      this.$http.post("/publisher/update",this.author1).then(add=>{
        //alert(add);
        if(add>0){
          alert("修改成功");
          window.location.reload();
        }else{
          alert("修改失败")
        }
      });
    },
  }
}
</script>

<style scoped>

</style>
